//
//  MainTabBar.swift
//  Weibo
//
//  Created by 杨雨哲 on 15/6/23.
//  Copyright © 2015年 yyz. All rights reserved.
//

import UIKit

class MainTabBar: UITabBar {
    
    private let buttonCount = 5

    override func layoutSubviews() {
        super.layoutSubviews()
        
        let w = bounds.width / CGFloat(buttonCount)
        
        let rect = CGRect(x: 0, y: 0, width: w, height: bounds.height)
        
        var index = 0
        
        for v in subviews{
            if v is UIControl && !(v is UIButton){
                v.frame = CGRectOffset(rect, w * CGFloat(index), 0)
                index += index == 1 ? 2 : 1
            }
        }
        
        compoesButton.frame = CGRectOffset(rect, 2 * w, 0)
    }
    
    lazy var compoesButton:UIButton = {
        
        let btn = UIButton()
        
        btn.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: UIControlState.Normal)
        btn.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: UIControlState.Highlighted)
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: UIControlState.Normal)
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: UIControlState.Highlighted)
        
        self.addSubview(btn)
        
        return btn
        
    }()

}
